<?php

namespace app\api\controller;
use app\index\model\Question;
use think\Controller;
use think\Db;

class Mini extends Controller
{
	
	public function get_question()
	{

		$where = [];

		$all_data = Db::name('question')
		->field('t1.*,t2.cate_name,t3.nickname,t3.face')
		->alias('t1')
		->join('cate t2','t1.cid = t2.cate_id')
        ->join('user t3','t1.user_id = t3.user_id')
        ->order('t1.create_time desc')
        ->where($where)
        ->limit(20)
		->select();

		foreach ($all_data as $k => $v) {
			$all_data[$k]['face'] = "http://1o533n8683.imwork.net/".$v['face'];
		}

		exit(json_encode(['code'=>0,'data'=>$all_data]));
	}

	public function get_detail()
	{
		$qid = input('qid');

		$all_data = Db::name('question')
		->field('t1.*,t2.cate_name,t3.nickname,t3.face')
		->alias('t1')
		->join('cate t2','t1.cid = t2.cate_id')
        ->join('user t3','t1.user_id = t3.user_id')
        ->order('t1.create_time desc')
		->find($qid);

		$all_data['face'] = "http://1o533n8683.imwork.net/".$all_data['face'];

		$all_data['content'] = strip_tags($all_data['content']);

		$all_data['content'] = str_replace("&nbsp;",'',$all_data['content']);

		$images = ["http://www.alimama.com/static/layui/images/face/1.gif"];

		exit(json_encode(['code'=>0,'data'=>$all_data,'images'=>$images]));
	}
}